local jushou = fk.CreateSkill {

  name = "joyex__jushou",

  tags = {  },

}



jushou:addEffect(fk.EventPhaseStart, {
  name = "joyex__jushou",
  anim_type = "offensive",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jushou.name) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:turnOver()
    if player.dead then return false end
    room:drawCards(player, 4, jushou.name)
    if player.dead then return false end
    local jushou_card
    for _, id in pairs(player:getCardIds(Player.Hand)) do
      local card = Fk:getCardById(id)
      if card.type == Card.TypeEquip and not player:prohibitUse(card) then
        jushou_card = card
        break
      end
    end
    if not jushou_card then return end
    local _, ret = room:askForUseActiveSkill(player, "#joyex__jushou_select", "#joyex__jushou-select", true)
    if ret then
      jushou_card = Fk:getCardById(ret.cards[1])
      if jushou_card then
        if jushou_card.type == Card.TypeEquip then
          room:useCard({
            from = player.id,
            tos = {{player.id}},
            card = jushou_card,
          })
        end
      end
    end
  end,
})

jushou:addEffect("active", {
  name = "#joyex__jushou_select",
  can_use = Util.FalseFunc,
  target_num = 0,
  card_num = 1,
  card_filter = function(self, player, to_select, selected)
    if #selected == 0 and Fk:currentRoom():getCardArea(to_select) ~= Card.PlayerEquip then
      local card = Fk:getCardById(to_select)
        return card.type == Card.TypeEquip and not player:prohibitUse(card)
    end
  end,
})

return jushou